package com.mytest.provider.es.controller;


import com.mytest.provider.es.serviceImpl.SearchService;
import com.mytest.provider.es.utils.SearchRequest;
import com.mytest.provider.es.utils.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索 分页查询
     */
    @PostMapping("page")
    public ResponseEntity<SearchResult> search(
            @RequestBody SearchRequest searchRequest
            ){
        SearchResult goodsPageResult = this.searchService.page(searchRequest);
        if (goodsPageResult!=null){
            return ResponseEntity.ok(goodsPageResult);
        }
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
